﻿using Guoc.BigMall.Domain.ValueObject;
using Guoc.BigMall.Infrastructure.Extension;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Guoc.BigMall.Domain.Service
{
    public class CodeSequenceService : ICodeSequenceService
    {
        /// <summary>
        /// 订单编号 ： 单据类型 2 +（日期20160101） 8 位+  账号3位+ 3位随机 =  18位长度
        /// </summary>
        /// <param name="billType"></param>
        /// <param name="createdBy"></param>
        /// <returns></returns>
        public string NewCode(BillIdentity billType, int createdBy)
        {
            string createdByNumber = createdBy > 9999 ? createdBy.ToString().Substring(0, 3) : createdBy.ToString().PadLeft(3, '0'); // 3位 
            string date = DateTime.Now.ToString("yyyyMMddHH");
            Random rd = new Random(Guid.NewGuid().GetHashCode());
            var rdNumber = rd.Next(100, 999);
            return string.Format("{0}{1}{2}{3}", billType.Value(), date, createdByNumber, rdNumber);
        }        
    }
}
